﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using hospital_registration_system.DAL;
using hospital_registration_system.Entity;
namespace hospital_registration_system.user
{
    public partial class userLogin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btn_Click(object sender, EventArgs e)
        {
            if (username.Text == null || pwd.Text == null) return;
            PatientsDao dao = new PatientsDao();
            Patients patient =null;
            if (IsEmail(username.Text))
            {
                patient = dao.LoginByEmail(username.Text, pwd.Text);
            }
            else
            {
                patient = dao.Login(username.Text, pwd.Text);
            }
            if (patient == null)
                return;
            else
            {
                Session.Add("patient",patient);
                Response.Redirect("/user/index.aspx");
            }
        }


        public bool IsEmail(string str)
        {
            foreach(char ch in str)
            {
                if (ch < '0' || ch > '9')
                    return true;
            }
            return false;
        }

    }
}